<%--
     商品编辑页面
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<html>
<head>
    <title>Title</title>
    <script src="../../js/jquery-3.3.1.min.js" charset="utf-8"></script>
    <script src="../../js/cookie/jquery.cookie.js" charset="utf-8"></script>
    <script src="../../layui-v2.2.5/layui/layui.js" charset="utf-8"></script>
    <link rel="stylesheet" href="../../layui-v2.2.5/layui/css/layui.css" media="all">
</head>
<body>
<form class="layui-form" action="/shop/saveCommodity">

    <%--图片数据--%>

    <input type="hidden" name="gameId" value="${gameId}">
    <table class="layui-table">
        <colgroup>
            <col width="150">
            <col width="200">
            <col>
        </colgroup>
        <thead>
        <tr>
            <th>答对时间</th>
            <th>折扣</th>
            <th style="width: 5rem">数量</th>
            <th>有效期</th>
            <th>淘宝口令</th>
        </tr>
        </thead>
        <tbody>
        <tr>
            <td>0-3s</td>
            <td><input type="text" value="${resultMap.discount0}" placeholder="折扣" name="discount0"   lay-verify="required"  required="required"></td>
            <td style="width: 5rem"><input type="text" value="${resultMap.number0}" placeholder="数量" name="number0"
                                           lay-verify="required"  required="required"></td>
            <td><input type="text" class="layui-input" id="test1" name="startDate0" value="${resultMap.startDate0}" lay-verify="required"  required="required">
                至<input type="text" class="layui-input" id="test5" name="endDate0" value="${resultMap.endDate0}" lay-verify="required"  required="required"></td>
            <td><textarea  style="height: 5rem;width: 18rem" name="command0" placeholder="淘宝口令">${resultMap.command0}</textarea></td>
        </tr>
        <tr>
            <td>4-7s</td>
            <td><input type="text" value="${resultMap.discount1}" placeholder="折扣" lay-verify="required" name="discount1"   required="required"></td>
            <td style="width: 5rem"><input type="text" value="${resultMap.number1}" placeholder="数量" name="number1" lay-verify="required"  required="required"></td>
            <td><input type="text" class="layui-input" id="test2" value="${resultMap.startDate1}" name="startDate1" lay-verify="required"  required="required">
                至<input type="text" class="layui-input" id="test6" name="endDate1" value="${resultMap.endDate1}" lay-verify="required"  required="required"></td>
            <td><textarea style="height: 5rem;width: 18rem"  name="command1" placeholder="淘宝口令">${resultMap.command1}</textarea></td>
        </tr>
        <tr>
            <td>8-10s</td>
            <td><input type="text" value="${resultMap.discount2}" placeholder="折扣" lay-verify="required" name="discount2"  required="required"></td>
            <td style="width: 5rem"><input type="text" value="${resultMap.number2}" placeholder="数量" name="number2" lay-verify="required"  required="required"></td>
            <td><input type="text" class="layui-input" id="test3" name="startDate2" value="${resultMap.startDate2}" lay-verify="required"  required="required">
                至<input type="text" class="layui-input" id="test7" name="endDate2" value="${resultMap.endDate2}" lay-verify="required"  required="required"></td>
            <td><textarea  style="height: 5rem;width: 18rem" name="command2" placeholder="淘宝口令">${resultMap.command2}</textarea></td>
        </tr>
        <tr>
            <td>安慰奖</td>
            <td><input type="text" value="${resultMap.discount3}" placeholder="折扣" name="discount3" lay-verify="required"  required="required"></td>
            <td style="width: 5rem"><input type="text" value="${resultMap.number3}" placeholder="数量" name="number3" lay-verify="required"  required="required"></td>
            <td><input type="text" class="layui-input" id="test4" name="startDate3" value="${resultMap.startDate3}" lay-verify="required"  required="required">
                至<input type="text" class="layui-input" id="test8" name="endDate3" value="${resultMap.endDate3}" lay-verify="required"  required="required"></td>
            <td><textarea style="height: 5rem;width: 18rem"  name="command3" placeholder="淘宝口令">${resultMap.command3}</textarea></td>
        </tr>
        </tbody>
    </table>


    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="formDemo">立即提交</button>
            <%--<button type="reset" class="layui-btn layui-btn-primary">重置</button>--%>
        </div>
    </div>
</form>

<script>
    //Demo
    layui.use('form', function(){
        var form = layui.form;

        //监听提交
        form.on('submit(formDemo)', function(data){
            //layer.msg(JSON.stringify(data.field));
            $.ajax({
                url:'/shop/saveRule',
                type:'POST', //GET
                async:true,    //或false,是否异步
                data:data.field,
                timeout:5000,    //超时时间
                dataType:'json',    //返回的数据格式：json/xml/html/script/jsonp/text
                beforeSend:function(xhr){
                    /*console.log(xhr)
                     console.log('发送前')*/
                },
                success:function(data){
                    console.log(data);
                    if (data.code=='000000'){
                        layer.msg(data.msg,{time:1000,icon: 6},function () {
                            var index = parent.layer.getFrameIndex(window.name);
                            //关闭当前frame
                            parent.layer.close(index);
                        });
                        // 获得frame索引

                    }else {
                        layer.msg(data.msg,{time:1000,icon: 5});
                    }
                    //console.log(data)
                },
                error:function(xhr,textStatus){
                    console.log('错误')
                    console.log(xhr)
                    console.log(textStatus)
                },
                complete:function(){
                    //console.log('结束')
                }
            });
            return false;
        });
    });



    layui.use('laydate', function(){
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#test1' //指定元素
            ,format: 'yyyy-MM-dd' //可任意组合
        });
        laydate.render({
            elem: '#test2' //指定元素
            ,format: 'yyyy-MM-dd' //可任意组合
        });
        laydate.render({
            elem: '#test3' //指定元素
            ,format: 'yyyy-MM-dd' //可任意组合
        });
        laydate.render({
            elem: '#test4' //指定元素
            ,format: 'yyyy-MM-dd' //可任意组合
        });
        laydate.render({
            elem: '#test5' //指定元素
            ,format: 'yyyy-MM-dd' //可任意组合
        });
        laydate.render({
            elem: '#test6' //指定元素
            ,format: 'yyyy-MM-dd' //可任意组合
        });
        laydate.render({
            elem: '#test7' //指定元素
            ,format: 'yyyy-MM-dd' //可任意组合
        });
        laydate.render({
            elem: '#test8' //指定元素
            ,format: 'yyyy-MM-dd' //可任意组合
        });
    });


</script>



</body>
</html>
